﻿
@{
    ViewBag.Title = "本科室人员测评";
    Layout = "~/Views/Shared/_EvalLayout.cshtml";
}

@model List<WebApp.ViewModels.Evaluate.WorkerMemberResultModel>

@section css{
    <style type="text/css">
        .result-desc{
            font-size:12px;
            font-weight:normal;
            color: #666;
        }
    </style>
}

<input type="hidden" id="evalId" value="@ViewBag.EvalId" />
<input type="hidden" id="deptId" value="@ViewBag.DeptId" />

<div class="jjdy_box w1320">
    <div class="jjdy_l left" style="width:100%;">
        <div class="bbs_list border">
            <div class="bbs_menu">当前位置：<a href="~/Eval/Index">大机段管理人员年度测评系统</a> &gt; @ViewBag.Title</div>
            <div class="bbscount_tit">
                <h1>
                    @ViewBag.Title
                    <span>（</span>
                    <span style="color:#ff6a00;">@ViewBag.DeptName</span>
                    <span>）</span>
                </h1>
            </div>
            <div class="bbs_count1">
                <div class="bbs_count_r" style="width:100%;">
                    <div class="bbs_count_neirong">
                        <table class="table table-bordered table-hover" id="resulttable">
                            <thead>
                                <tr>
                                    <th rowspan="2" style="width:7%;">照片</th>
                                    <th rowspan="2" style="width:7%;">姓名</th>
                                    <th rowspan="2" style="width:7%;">职务</th>
                                    <th rowspan="2" style="width:7%;">工作分工</th>
                                    <th class="split" colspan="4">德<br /><span class="result-desc">自觉贯彻执行党的路线、方针、政策；秉公办事，言行一致，为人正派</span></th>
                                    <th class="split" colspan="4">能<br /><span class="result-desc">专业知识熟练，有良好的管理意识和管理能力，有独立思考和解决问题的能力</span></th>
                                    <th class="split" colspan="4">勤<br /><span class="result-desc">工作积极主动，遇事不推诿，办事不拖拉，工作效率高，不计较个人得失</span></th>
                                    <th class="split" colspan="4">绩<br /><span class="result-desc">按时按质地完成本职工作，管理工作规范，分管工作开展有序</span></th>
                                    <th class="split" colspan="4" style="padding:8px 3px;">廉<br /><span class="result-desc">自觉执行党风廉政各种制度，廉洁自律，不以权谋私，无违反党纪、政纪的行为</span></th>
                                </tr>
                                <tr>
                                    <th class="split" style="width:3.5%;">@(ViewBag.ResultName_1)</th>
                                    <th style="width:3.5%;">@(ViewBag.ResultName_2)</th>
                                    <th style="width:3.5%;">@(ViewBag.ResultName_3)</th>
                                    <th style="width:3.5%;">@(ViewBag.ResultName_4)</th>
                                    <th class="split" style="width:3.5%;">@(ViewBag.ResultName_1)</th>
                                    <th style="width:3.5%;">@(ViewBag.ResultName_2)</th>
                                    <th style="width:3.5%;">@(ViewBag.ResultName_3)</th>
                                    <th style="width:3.5%;">@(ViewBag.ResultName_4)</th>
                                    <th class="split" style="width:3.5%;">@(ViewBag.ResultName_1)</th>
                                    <th style="width:3.5%;">@(ViewBag.ResultName_2)</th>
                                    <th style="width:3.5%;">@(ViewBag.ResultName_3)</th>
                                    <th style="width:3.5%;">@(ViewBag.ResultName_4)</th>
                                    <th class="split" style="width:3.5%;">@(ViewBag.ResultName_1)</th>
                                    <th style="width:3.5%;">@(ViewBag.ResultName_2)</th>
                                    <th style="width:3.5%;">@(ViewBag.ResultName_3)</th>
                                    <th style="width:3.5%;">@(ViewBag.ResultName_4)</th>
                                    <th class="split" style="width:3.5%;">@(ViewBag.ResultName_1)</th>
                                    <th style="width:3.5%;">@(ViewBag.ResultName_2)</th>
                                    <th style="width:3.5%;">@(ViewBag.ResultName_3)</th>
                                    <th style="width:3.5%;">@(ViewBag.ResultName_4)</th>
                                </tr>
                            </thead>
                            <tbody class="list-data">
                                @foreach (var member in Model)
                                {
                                    <tr data-memberid="@(member.Member_id)">
                                        <td class="text-center" style="padding:0;"><img src="@Href("~/")Eval/AvatarImage?path=@(member.Avatarurl)" style="height:100px;width:80px;" /></td>
                                        <td class="text-center">
                                            @(member.Membername)
                                            <input type="hidden" id="result_1_@(member.Member_id)" class="datafield" value="@(member.Result_1)" data-fieldname="Result_1" />
                                            <input type="hidden" id="result_2_@(member.Member_id)" class="datafield" value="@(member.Result_2)" data-fieldname="Result_2" />
                                            <input type="hidden" id="result_3_@(member.Member_id)" class="datafield" value="@(member.Result_3)" data-fieldname="Result_3" />
                                            <input type="hidden" id="result_4_@(member.Member_id)" class="datafield" value="@(member.Result_4)" data-fieldname="Result_4" />
                                            <input type="hidden" id="result_5_@(member.Member_id)" class="datafield" value="@(member.Result_5)" data-fieldname="Result_5" />
                                        </td>
                                        <td class="text-center">@(member.Job)</td>
                                        <td class="text-center">@(member.Remark)</td>
                                        <td class="text-center col-alt split"><a class="eval-checkbox" data-fieldname="Result_1" data-value="10"></a></td>
                                        <td class="text-center col-alt"><a class="eval-checkbox" data-fieldname="Result_1" data-value="20"></a></td>
                                        <td class="text-center col-alt"><a class="eval-checkbox" data-fieldname="Result_1" data-value="30"></a></td>
                                        <td class="text-center col-alt"><a class="eval-checkbox" data-fieldname="Result_1" data-value="40"></a></td>
                                        <td class="text-center split"><a class="eval-checkbox" data-fieldname="Result_2" data-value="10"></a></td>
                                        <td class="text-center"><a class="eval-checkbox" data-fieldname="Result_2" data-value="20"></a></td>
                                        <td class="text-center"><a class="eval-checkbox" data-fieldname="Result_2" data-value="30"></a></td>
                                        <td class="text-center"><a class="eval-checkbox" data-fieldname="Result_2" data-value="40"></a></td>
                                        <td class="text-center col-alt split"><a class="eval-checkbox" data-fieldname="Result_3" data-value="10"></a></td>
                                        <td class="text-center col-alt"><a class="eval-checkbox" data-fieldname="Result_3" data-value="20"></a></td>
                                        <td class="text-center col-alt"><a class="eval-checkbox" data-fieldname="Result_3" data-value="30"></a></td>
                                        <td class="text-center col-alt"><a class="eval-checkbox" data-fieldname="Result_3" data-value="40"></a></td>
                                        <td class="text-center split"><a class="eval-checkbox" data-fieldname="Result_4" data-value="10"></a></td>
                                        <td class="text-center"><a class="eval-checkbox" data-fieldname="Result_4" data-value="20"></a></td>
                                        <td class="text-center"><a class="eval-checkbox" data-fieldname="Result_4" data-value="30"></a></td>
                                        <td class="text-center"><a class="eval-checkbox" data-fieldname="Result_4" data-value="40"></a></td>
                                        <td class="text-center col-alt split"><a class="eval-checkbox" data-fieldname="Result_5" data-value="10"></a></td>
                                        <td class="text-center col-alt"><a class="eval-checkbox" data-fieldname="Result_5" data-value="20"></a></td>
                                        <td class="text-center col-alt"><a class="eval-checkbox" data-fieldname="Result_5" data-value="30"></a></td>
                                        <td class="text-center col-alt"><a class="eval-checkbox" data-fieldname="Result_5" data-value="40"></a></td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="bbs_count_r" style="margin:0 0 20px 20px;">
                    @if (ViewBag.CanEdit)
                    {
                        <button id="btnsubmit" class="btn btn-lg btn-primary">提交</button>
                    }
                    else
                    {
                        <button id="btnsubmit" disabled="disabled" class="btn btn-lg btn-default">提交</button>
                    }
                </div>
            </div>
        </div>
    </div>

</div>

@section scripts{
    <script type="text/javascript">
        var canEdit = @(ViewBag.CanEdit ? "true": "false");

        $(document).ready(function () {
            $(".eval-checkbox").click(function (e) {
                if(!canEdit) return;

                var $row = $(this).closest("tr");
                var fieldname = $(this).attr("data-fieldname");
                var memberId = $row.attr("data-memberid");
                $row.find(".eval-checkbox[data-fieldname=" + fieldname + "]").removeClass("checked");
                $(this).addClass("checked");

                var value = $(this).attr("data-value");
                $row.find("input[data-fieldname=" + fieldname + "]").val(value);

                //保存结果
                saveResult(memberId, fieldname, value);
            });
            
            $(".datafield").each(function () {
                var $row = $(this).closest("tr");
                var fieldname = $(this).attr("data-fieldname");
                var value = $(this).val();
                $row.find("[data-fieldname='" + fieldname + "'][data-value='" + value + "']").addClass("checked");
            });

            $("#btnsubmit").click(function (e) {
                e.preventDefault();

                if (!canEdit) return;

                var isvalid = true;
                $(".datafield").each(function () {
                    if ($(this).val() == "") {
                        //$(this).closest("tr").addClass("error");
                        isvalid = false;
                    }
                });
                if (!isvalid) {
                    alert("所有人员测评结果必须都填写完整！");
                    return;
                }

                if (confirm("结果提交后不能再修改，确认要提交测评结果吗？")) {
                    submitResult();
                }
            });

            if (!canEdit) {
                setTimeout(function () {
                    alert("您的测评结果已提交，不能修改！");
                }, 100);
            }
        });

        function saveResult(memberId, fieldname, result) {
            $.ajax({
                url: baseurl + 'Eval/SaveWorkerMemberItemResult',
                method: 'post',
                data: {
                    evalId: $("#evalId").val(),
                    deptId: $("#deptId").val(),
                    memberId: memberId,
                    fieldname: fieldname,
                    result: result
                },
                success: function (result) {
                    //console.log(result);
                }
            });
        }

        function submitResult() {
            $.ajax({
                url: baseurl + 'Eval/SubmitWorkerMemberItemResult',
                method: 'post',
                data: {
                    evalId: $("#evalId").val(),
                    deptId: $("#deptId").val()
                },
                success: function (result) {
                    alert("提交成功！");
                    location.href = baseurl + "Eval/Index";
                }
            });
        }
    </script>
}